package mogowtools.client.fx;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.ui.UIObject;
import com.google.gwt.user.client.Element;

public class Style 
{
	private String cssAttribute;
	private JavaScriptObject effect;
	private Element elem;
	private Options options;
	
	public Style(UIObject element, String attr, Options opts)
	{
		this.elem = element.getElement();
		this.options = opts;
		this.cssAttribute = attr;
		this.effect = newStyleObject();
	}

	public Style(UIObject element, String attr)
	{
		this.elem = element.getElement();
		this.options = new Options();
		this.cssAttribute = attr;
		this.effect = newStyleObject();
	}
	
	public void start(String begin, String end)
	{
		startAnim(begin, end);
	}
	
	public void start(String end)
	{
		startAnim(end);
	}
	
	public void stop()
	{
		stopAnim();
	}
	
	public void set(String value)
	{
		setValue(value);
	}
	
	public void addListener(StyleListener s)
	{
		this.options.addStyleListener(s);
	}
	
	public JavaScriptObject getOptions()
	{
		return this.options.value();
	}
	
	private native JavaScriptObject newStyleObject()
	/*-{
		return new $wnd.Fx.Style(
			this.@mogowtools.client.fx.Style::elem, 
			this.@mogowtools.client.fx.Style::cssAttribute, 
			this.@mogowtools.client.fx.Style::getOptions()());
	}-*/;
	
	private native void startAnim(String begin, String end)
	/*-{
	 var fx = this.@mogowtools.client.fx.Style::effect;
	 fx.start(begin, end);
	}-*/;
	
	private native void startAnim(String end)
	/*-{
	 var fx = this.@mogowtools.client.fx.Style::effect;
	 fx.start(end);
	}-*/;
	
	private native void stopAnim()
	/*-{
	 var fx= this.@mogowtools.client.fx.Style::effect;
	 fx.stop();
	}-*/;
	
	private native void setValue(String value)
	/*-{
	 var fx = this.@mogowtools.client.fx.Style::effect;
	 fx.set(value);
	}-*/;
}

